﻿Public Class frmCabinetEXP
    Public pCode_cab As Integer
    Public pCode_exp As Integer

    Private szSQL As String
    Private rs As ADODB.Recordset

    Private Sub frmExpert_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Me.Text = "Fiche EXPERT : " & pCode_cab & " - " & pCode_exp
        ExpertToScreen()

    End Sub

    Private Sub ExpertToScreen()

        ' Nouvelle Création ?
        If pCode_exp = 0 Then
            ' RAB des champs du form
            ClearTextBoxes(Me)
            ChkEN_ACTIVITE.Checked = True
        Else
            'Lire l'expert
            szSQL = "CALL spGET_EXPERTS('" & gSocieteCode & "'," & pCode_cab & "," & pCode_exp & ")"
            GetRecordset(ctDSN_DEVFAC, szSQL, rs)
            If rs.RecordCount < 1 Then
                rs.Close()
                Exit Sub
            End If

            TE_NOM.Text = rs.Fields("nom").Value
            TE_TEL1.Text = nv(rs.Fields("tel1").Value)
            TE_TEL2.Text = nv(rs.Fields("tel2").Value)
            TE_EMAIL.Text = nv(rs.Fields("email").Value)
            ChkEN_ACTIVITE.Checked = rs.Fields("en_activite").Value
            rs.Close()

        End If

    End Sub

    Private Sub BO_ENREGISTER_Click(sender As System.Object, e As System.EventArgs) Handles BO_ENREGISTER.Click

        If IsUserAuthorised(ctGestion) = False Then
            Exit Sub
        End If

        szSQL = "CALL spUPD_P_EXPERTS('" & gSocieteCode & "'," & pCode_cab & "," & pCode_exp & ",'" & nq(TE_NOM.Text) & "','" & _
         TE_TEL1.Text & "','" & TE_TEL2.Text & "'," & CInt(ChkEN_ACTIVITE.Checked) & ",'" & TE_EMAIL.Text & "');"
        ExecQuery(ctDSN_DEVFAC, szSQL)

        ' fermer la fenetre1
        Me.Close()

    End Sub

    Private Sub BO_SUPPRIMER_Click(sender As System.Object, e As System.EventArgs) Handles BO_SUPPRIMER.Click

        If IsUserAuthorised(ctCompta) = False Then
            Exit Sub
        End If
        ' utilisateur autorisé à supprimer ?
        If IsUserAuthorised(9) = False Then
            Exit Sub
        End If
        If pCode_exp = "1" Then
            MsgBox("Il est interdit de supprimer l'expert Indéterminé !")
            Exit Sub
        End If

        deleteEnregistrement("P_EXPERTS", TE_NOM.Text, pCode_cab, pCode_exp)
        ' ferme la fenetre
        Me.Close()

    End Sub

End Class